from cmath import inf
from typing import List
import json


class Solution:
    def findRestaurant(self, list1: List[str], list2: List[str]) -> List[str]:
        # list1 差集
        print(set(list1).difference(set(list2)))
        # list1 并集
        print(set(list1).union(set(list2)))
        # 1、map构造函数具有将(value, index)的列表转换为dict的功能,该函数产生(index, value)的tuple
        # map应该是(value, index), reversed将元组元素反转: dict(map(reversed, enumerate(lst)))
        print("map reversed: ", dict(map(reversed, enumerate(list1))))
        # 2、不要使用list作为变量名，因为它是Python保留的变量
        # dict = {key: i for i, key in enumerate(your_list)}
        print("enumerate:", {key: i for i, key in enumerate(list1)})

        dict1 = {key: i for i, key in enumerate(list1)}
        dict2 = {key: i for i, key in enumerate(list2)}

        # 交集
        intersection1 = {key:i for key, i in dict1.items() if key in dict2}
        print("intersection1: ", intersection1)
        intersection2 = {key:i for key, i in dict2.items() if key in dict1}
        print("intersection2: ", intersection2)

        dict3 = {key: i for i, key in enumerate(list1)}
        ans = []
        indexSum = inf # 无穷大？
        for i, v in enumerate(list2):
            if v in dict3:
                j = dict3[v]
                if i + j < indexSum:
                    indexSum = i + j
                    # ['KFC', 'Shogun']
                    # ans.append(v) # 为啥用 append 错了？？
                    # append是追加, [v]是重新赋值!!!!
                    ans = [v]
                    print("ans1: ", ans)
                elif i + j == indexSum:
                    ans.append(v)
                    print("ans2: ", ans)
        # 输入不能打断点？？？教育版不能打断点？？
        return ans


def main():
    import sys
    import io
    def readlines():
        for line in io.TextIOWrapper(sys.stdin.buffer, encoding='utf-8'):
            yield line.strip('\n')

    lines = readlines()
    while True:
        try:
            line1 = next(lines)
            list1 = json.loads(line1)
            line2 = next(lines)
            list2 = json.loads(line2)

            ret = Solution().findRestaurant(list1, list2)

            # out = (ret,)
            out = (ret)
            print(type(out))
            print(out)
        except StopIteration:
            break

if __name__ == '__main__':
    main()